<template>
	<view class="content">
		<u-navbar leftIconColor="#000" :autoBack="true" :placeholder="true" bgColor="rgba(255,255,255,0.0)">
			<view slot="center" class="nav-title">
				全部订单
			</view>
		</u-navbar>
		<!-- <u-tabs :list="tabslist" @click="tabsclick" :current="current" :inactiveStyle="{ color: '#666'}"
			lineColor="#FD5674" :activeStyle="{ color: '#FD5674' }"></u-tabs> -->
		<view class="tabs">
			<view :class="current == index ?'active-item':'tabs-item'" class="tabs-item"
				v-for="(item,index) in tabslist" :key="index" @click="tabsclick(index)">
				{{item.name}}
			</view>
		</view>
		<view v-if="list.length > 0">
			<view class="info"  v-for="(item,index) in list" :key="index">
				<view class="info-top" v-if="item.track_number">
					<view class="order-num">
						快递单号：{{item.track_number}}
					</view>
					<view class="copy" @click="gocory(item.track_number)">
						复制
					</view>
				</view>
				<view class="info-cont">
					<image :src="item.goods_logo" mode=""></image>
					<view class="cont-right">
						<view class="right-name">
							{{item.goods_name}}
						</view>
						<view class="right-num">
							x{{item.goods_num}}
						</view>
					</view>
				</view>
				<view class="order-type">
					<view>
						状态
					</view>
					<view class="type">
						{{item.type}}
					</view>
				</view>
			</view>
		</view>
		<view v-else>
			<u-empty mode="list" icon="../../../static/home/none.png" :marginTop="100" text="订单列表为空">
			</u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabslist: [{
					name: '待发货',
				}, {
					name: '已发货',
				}, {
					name: '已完成',
				}, {
					name: '已取消',
				}],
				current: 1,
				list: [],
				page: 1
			}
		},
		onLoad(e) {
			this.current = Number(e.cutt)
			this.postlist()
		},
		onReachBottom() {
			this.page = this.page + 1
			this.postlist()
		},
		methods: {
			gocory(num){
				uni.setClipboardData({
					data: num,
					success: function () {
						console.log('success');
						uni.showToast({
							title:'复制成功！',
							icon:'none'
						})
					}
				});
			},
			gobuy(item) {
				const app = this
				uni.showModal({
					title: '提示',
					content: '是否确定收货！',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							let params = {
								id: item.id
							}
							uni.showLoading({
								mask: true
							})
							app.$Request({
								method: 'POST',
								url: '/api/shop/orderComplete',
								data: params
							}).then(res => {
								uni.hideLoading()
								if (res.code == 1) {
									uni.showToast({
										title: '收货成功！',
										icon: 'none'
									})
									app.page = 1
									app.postlist()
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			postlist() {
				let params = {
					type: this.current + 1,
					page: this.page
				}
				this.$Request({
					method: 'POST',
					url: '/api/shop/orderList',
					data: params
				}).then(res => {
					if (res.code == 1) {
						if (this.page == 1) {
							this.list = res.data.list
						} else {
							this.list = [...this.list, ...res.data.list]
						}

					}
				})
			},
			tabsclick(index) {
				this.current = index
				this.page = 1
				this.list = []
				this.postlist()
			}
		}
	}
</script>

<style>
	page {
		background-color: #f8f8f8;
	}
</style>
<style scoped lang="scss">
	.content {
		min-height: 100vh;
		background-image: url('../../../static/home/home-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 500rpx;
		padding: 0 30rpx 100rpx 30rpx;

		.tabs {
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: rgba(255, 255, 255, 0.7);
			opacity: 0.9;
			border-radius: 20rpx;
			border: 1px solid #FFFFFF;
			padding: 15rpx;
			.tabs-item {
				width: 22%;
				font-size: 26rpx;
				font-weight: 500;
				color: #8F8F8F;
				text-align: center;
				padding: 15rpx 0;
			}
		
			.active-item {
				background-color: #FFFFFF;
				border-radius: 10rpx;
				color: #000000;
			}
		}

		.info {
			padding: 30rpx;
			margin-bottom: 30rpx;
			background: #fff;
			border-radius: 30rpx;
			margin-top: 20rpx;
			.info-top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 20rpx;
				.order-num {
					font-size: 28rpx;
					color: #999999;
				}
				.copy {
					font-size: 26rpx;
					color: #FF7F7F;
					border: 2rpx solid #FF7F7F;
					padding: 5rpx 15rpx;
					border-radius: 10rpx;
				}
			}
			.info-cont {
				display: flex;
				align-items: center;
				image {
					width: 96rpx;
					height: 96rpx;
					border-radius: 10rpx;
				}
				.cont-right {
					margin-left: 20rpx;
					.right-name {
						font-size: 32rpx;
						color: #333333;
					}
					.right-num {
						font-size: 24rpx;
						color: #999999;
						margin-top: 10rpx;
					}
				}
			}
			.order-type {
				display: flex;
				justify-content: space-between;
				padding: 20rpx;
				border-radius: 20rpx;
				background-color: #F8F8F8;
				margin-top: 20rpx;
				font-size: 28rpx;
				.type {
					color: #FF7F7F;
				}
			}
		}
	}
</style>